package org.example.controller;

import org.example.bean.req.UserLoginReq;
import org.example.utils.AESUtil;
import org.example.utils.RedisKeyUtil;
import org.example.utils.SessionUser;
import org.example.utils.redis.ServerRedisClient;
import org.example.utils.redis.impl.ServerJedisClientImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import org.apache.commons.lang3.StringUtils;

@RestController()
@RequestMapping("/user")
public class UserController {


    @Autowired
    private ServerRedisClient jedisClient;
    @PostMapping("/login")
    String login(@RequestBody UserLoginReq userLoginReq){
        System.out.println(userLoginReq);
        String userToken = AESUtil.encryptBase64(AESUtil.USER_TOKEN_KEY,userLoginReq.getAccount());
        String key = String.format(RedisKeyUtil.USER_LOGIN_TOKEN_KEY, userToken);
        String accountAppId = jedisClient.hget(key, "appId");
        jedisClient.set("1","1");
        System.out.println(jedisClient.get("1"));
//        if(StringUtils.isNotEmpty(accountAppId) && accountAppId.equals(appId)){
//            jedisClient.hset(key, "role",String.valueOf(req.getRole()));
//            jedisClient.expire(key, BlueCatConstants.TOKEN_TIME_OUT);
//        }
        return "登录成功!";
    }
    @PostMapping("/info")
    Object info(){
        return  SessionUser.getUserInfoVO();
    }
}
